#include "MDataMap.h"

MDataMap::MDataMap()
{
}

MDataMap::MDataMap(MMap *map)
{
    int i;

    i = 0;
    while (i < (80 * 60))
    {
        if ((map->table)[i] != NULL)
        {
            if ((map->table)[i]->type == MCASE_BUILDING)
            {
                (this->table_building)[i] = *((MBuilding *)((map->table)[i]));
                (this->table_gates)[i].type = MCASE_NULL;
            }
            else if ((map->table[i]->type) == MCASE_GATE)
            {
                (this->table_gates)[i] = *((MGate *)((map->table)[i]));
                (this->table_building)[i].type = MCASE_NULL;
            }
        }
        else
        {
            (this->table_building)[i].type = MCASE_NULL;
            (this->table_gates)[i].type = MCASE_NULL;
        }
        i += 1;
    }
    this->grid = map->grid;
}

MDataMap::~MDataMap()
{
}

MMap *MDataMap::get_map()
{
    MMap *map;
    int i;

    map = new MMap();
    i = 0;
    while (i < (80 * 60))
    {
        if ((this->table_building)[i].type == MCASE_BUILDING)
            (map->table)[i] = new MBuilding(i % 80, i / 80);
        else if ((this->table_gates)[i].type == MCASE_GATE)
            (map->table)[i] = new MGate(i % 80, i / 80, (this->table_gates)[i].ip, (this->table_gates)[i].port);
        i += 1;
    }
    map->grid = this->grid;
    return map;
}
